<?php

declare(strict_types=1);
/*
 * This file is part of Leonsw.
 *
 * @link     https://leonsw.com
 * @document https://docs.leonsw.com
 * @contact  leonsw.com@gmail.com
 * @license  https://leonsw.com/LICENSE
 */
namespace App\Resource\Activity;

use App\Models\MainDB\Coin;
use App\Models\MainDB\MallProducts;
use Illuminate\Http\Resources\Json\JsonResource;

class Resource extends JsonResource
{
    public function toArray($request)
    {
        if ($this->reward_type === Coin::RELATION_TYPE) {
            $name = $this->count. $this->reward->name;
        } else {
            $name = $this->reward->name ?? $this->reward->title;
        }
        return [
            'id'          => $this->id ?? null,
            'reward_id'   => $this->reward->id ?? null,
            'name'        => $name,
            'image'       => $this->reward->picture ?? null,
            'type'        => $this->reward_type ?? null,
            'count'       => $this->count ?? null,
        ];
    }
}
